<template>
  <div class="header-frame">
      <el-row type="flex" justify="space-between">
          <el-col :span="6" class="left-header">
              <div class="header-logo">
                  <img class="logo" src="@/assets/logo.png" alt="">
                  <h1>财务管理系统</h1>
              </div>
          </el-col>
          <el-col :span="6" class="right-header">
              <div class="user-info">
                    <img :src="avatar" alt="">
                    <div>
                        <p>欢迎</p>
                        <p :title="userName" class="user-name">{{userName}}</p>
                    </div>
                  <div class="drop-down">
                    <el-dropdown trigger="click" @command="dropCommand">
                        <span class="el-dropdown-link">
                        <i class="el-icon-caret-bottom icon-caret-down"></i>
                        </span>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item command="info">用户信息</el-dropdown-item>
                            <el-dropdown-item command="loginOut">退出</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                  </div>
              </div>
          </el-col>
      </el-row>
  </div>
</template>

<script>
export default {
  name: 'FinanceHeader',
  data () {
      return {

      };
  },
  computed:{
      userName(){
        return this.$store.state.user.userName;
      },
      identity(){
        return this.$store.state.user.identity==="manager"?"管理员":"员工";
      },
      avatar(){
        return this.$store.state.user.avatar;
      }
  },
  methods:{
    dropCommand(value){
        switch (value) {
            case "info":
                this.infoView()
            break ;
            case "loginOut":
                this.dropOut();
            break;
        }
    },
    infoView(){
        this.$router.push({path:"/main/perinfo"}); 
    },
    dropOut(){
        localStorage.removeItem("eletoken");
        this.$store.dispatch("setAuthenticated",false);
        this.$store.dispatch("setUser",{});
        this.$router.push({path:"/login"}); 
    }
  }
}
</script>

<style scoped>
.user-name{
    width: 1.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}
.icon-caret-down{
    color: #fff;
}
.user-info{
    display: flex;
    justify-content: flex-end;
    padding-right: 0.5rem;
    align-items: center;
    height: 2rem;
}
.user-info img{
    height: 1rem;
    width: 1rem;
    margin-right: 0.2rem;
    border-radius: 100%;
}
.user-info p{
    line-height: 0.5rem;
    color: #fff;
    font-size: 0.3rem;
}
.header-frame{
    height: 2rem;
    background: #2d374f;
}
.logo{
    padding-top: 0.2rem;
    height: 1.6rem;
    width: 1.6rem;
}
.header-logo{
    display: flex;
    height: 2rem;
    line-height: 2rem;
}
.header-logo h1{
    margin-left: 0.3rem;
    font-size: 0.7rem;
    color: #fff;
    font-weight: 600;
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
}
</style>
